﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SisLegal.Model; 

namespace SisLegal.Maestros
{
    public partial class CrimeSubGenericNewForm : System.Web.UI.Page
    {
        CrimeGenericManager crimeGeneric;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                crimeGeneric = new CrimeGenericManager();
                DDL_Generic.DataSource = crimeGeneric.GetAll();
                DDL_Generic.DataTextField = "Name";
                DDL_Generic.DataValueField = "ID";
                DDL_Generic.DataBind();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            CrimeSubGenericManager crimeManager = new CrimeSubGenericManager();
            CrimeSubGeneric crime = new CrimeSubGeneric();
            crime.Name = txtName.Text;
            crime.IDGeneric = Convert.ToInt32(DDL_Generic.SelectedItem.Value);
            int newArticleID = crimeManager.Save(crime);

            if (newArticleID != 0)
            {
                lblConfirmation.Text = "Grabado Satifactoriamente";
                lblConfirmation.Visible = true;
            }
            else
            {
                lblConfirmation.Text = "Error en la Grabacion";
                lblConfirmation.Visible = true;
            }

            ClearForm();
        }

        private void ClearForm()
        {
            txtName.Text = String.Empty;
        }
    }
}